﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Media.Imaging;
using AForge.Imaging;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ThreadSafeObjects;
using BrainTechLLC.FilterExtensions;
using BrainTechLLC.ImageOperators;

namespace ImageAppDataModels
{
    public static class DetermineBlurIFileImage
    {
        public static double PrepImages(this IFileImage f1, double scaleFactor, FilterCollection fc, bool makeCopies, out Bitmap bm1Final, bool wantPostProcessInfo, out List<RGBAndCoordinate> postProcessInfo1, out int width, out int height)
        {
            Bitmap bmp1 = (makeCopies) ? f1.EnsureBitmapLoaded().Clone() as Bitmap : f1.EnsureBitmapLoaded();
            return DetermineBlur.PrepImages(bmp1, f1.OriginalBitmapWidth, f1.OriginalBitmapHeight, scaleFactor, fc, makeCopies, out bm1Final, wantPostProcessInfo, out postProcessInfo1, out width, out height);
        }

        public static double BlurMeasure(this IFileImage f1, bool makeCopies)
        {
            Bitmap bm1 = null;

            if (makeCopies)
            {
                try
                {
                    bm1 = f1.EnsureBitmapLoaded().Clone() as Bitmap;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
            else
            {
                bm1 = f1.EnsureBitmapLoaded();
            }

            if (bm1 == null || (f1 as FileImage).OriginalBitmapWidth == 0)
            {
                return double.NaN;
            }

            return DetermineBlur.BlurMeasure(bm1, (f1 as FileImage).OriginalBitmapWidth, (f1 as FileImage).OriginalBitmapHeight, (f1 as FileImage).OriginalBitmapWidth, (f1 as FileImage).OriginalBitmapHeight, makeCopies);
        }

        public static double BlurMeasure(this IFileImage f1, double scaleFactor, bool makeCopies)
        {
            Bitmap bm1 = f1.EnsureBitmapLoaded();            
            return DetermineBlur.BlurMeasure(bm1, f1.OriginalBitmapWidth, f1.OriginalBitmapHeight, scaleFactor, makeCopies);
        }
    }
}
